﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects.DataClasses;
using System.Globalization;
using System.ComponentModel;
using System.Reflection;

namespace DalEntity
{


    public partial class Cliente : Modelo.Interface.IBaseBD
    {
        ShippingEntities db;
        
        public IList<T> RetornaGeral<T>() where T : class, new()
        {
            db = new ShippingEntities();
            List<T> retorno = new List<T>();
            foreach(Cliente C in db.Cliente.ToList())
            {
                T valor = GenericTypeConverter.ConvertType<Cliente, T>(C);
                retorno.Add(valor);

            }//return (T?)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(s);
            //List<T> teste = new List<T>((IEnumerable<T>)db.Cliente.ToList());
            return retorno;
        }

        public T RetornaBasePorID<T>(int id) where T : class, new()
        {
            db = new ShippingEntities();

            return GenericTypeConverter.ConvertType<Cliente, T>(db.Cliente.SingleOrDefault(c => c.Id == id));
        }

        public object RetornaInstancia<T>(T obj) where T : class, new()
        {
            {
                return GenericTypeConverter.ConvertType<T, Cliente>(obj);

                // return null;
            }
        }
    }

    

  



    //    using System.Reflection;

   

}
